<template>
	<view class="page">
		<view>

			<view class="u-padding-20 u-font-weight">个人资料</view>
			<u-form :model="form" ref="uForm" label-width="150">
				<view style="background: #FFFFFF;">


					<view style="padding: 0 30rpx;">
						<u-form-item label="姓名" prop="username">
							<u-input v-model="form.username" />
						</u-form-item>

						<u-form-item label="身份证" prop="id_number">
							<u-input v-model="form.id_number" />
						</u-form-item>
					</view>


					<view style="padding: 30rpx 0 0 30rpx;color: #6C6C6C;">请上传身份证正反照片</view>
					<view class="u-flex u-row-between u-padding-20">
						<view class="">
							<wr-upload_img ref="card_1" type="image" @uploaded="uploaded" :afterLoadUrl="form.card_1"
								defaultLength="1" width="320" height="200" cutType="" borderRadius="20" icon=""
								bgUrl="/images/card_1.png">
							</wr-upload_img>
							<view class="u-margin-top-15" style="text-align: center;color: #6C6C6C;">
								点击上传身份证正面
							</view>
						</view>
						<view class="">
							<wr-upload_img ref="card_2" type="image" @uploaded="uploaded" :afterLoadUrl="form.card_2"
								defaultLength="1" width="320" height="200" cutType="" borderRadius="20" icon=""
								bgUrl="/images/card_2.png">
							</wr-upload_img>
							<view class="" style="text-align: center;color: #6C6C6C;margin-top: 10rpx;">
								点击上传身份证反面
							</view>
						</view>

					</view>
					<view class="u-padding-20 u-border-top" style="color: #6C6C6C;text-align: center;">
						拍摄时请确保身份证<text style="color: #EF8139;">边框完整 字体清晰</text>
					</view>
				</view>


				<view class="u-padding-20 u-font-weight">上传相关职业资格证</view>


				<view class="u-flex " style="margin: auto;padding: 40rpx 0 0rpx 50rpx;background: #fff;">

					<wr-upload_img background="#f5f5f5" iconsize="80" iconColor="#00C08D" icontxt="上传职业资格证" ref="about"
						type="image" borderRadius="20" width="650" :afterLoadUrl="form.about" defaultLength="1"
						icon="camera-fill">
					</wr-upload_img>
				</view>
				
		
				<view class="" style="width: 600rpx;margin:40rpx auto;font-size: 20rpx;">
					<u-checkbox-group>
						<u-checkbox v-model="isread" :label-disabled="true">
							请认真阅读<text @click="read(2)">《用户服务协议及隐私政策》</text>
							</u-checkbox>
					</u-checkbox-group>
				</view>


				<view class="bottomFix">
					<u-button @click="submit" type="primary" :custom-style="{background:'#00C08D'}" shape="circle">立即申请
					</u-button>
				</view>



			</u-form>
			<u-toast ref="uToast" />

		</view>

	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isread:false,
				form: {
					
					card_1: "",
					card_2: "",
					about: "",
					
					
					id_number: "",
					username: "",
				},

				rules: {
					username: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
					id_number: [{
								required: true, 
								message: '请输入身份证',
								trigger: ['change','blur'],
							},
							{
								// 自定义验证函数，见上说明
								validator: (rule, value, callback) => {
									// 上面有说，返回true表示校验通过，返回false表示不通过
									// this.$u.test.mobile()就是返回true或者false的
									return this.$u.test.idCard(value);
								},
								message: '身份证不正确',
								// 触发器可以同时用blur和change
								trigger: ['change','blur'],
							}]
				}

			};
		},
		methods: {
			read(e){
				uni.navigateTo({
					url:'../about/index?id='+e
				})
			},
             jiazai(){
				this.$u.post('/user/index', {
				}).then(res => {
					
					if(res.is_auth){
						this.form=res;
						let card_1=res.auth_images_arr[0];
						let card_2=res.auth_images_arr[1];
						let about=res.auth_images_arr[2];
						
						this.form.card_1=card_1;
						this.form.card_2=card_2;
						this.form.about=about;
					}
				
					
				}).catch(err => {})
			},
			submit() {
			   if(!this.isread){
				   this.$u.toast("请认真阅读协议")
				   return
			   }
			   
				this.$refs.uForm.validate(valid => {
					if (valid) {
						let card_1 = this.$refs.card_1.afterUploadImgList;
						let card_2 = this.$refs.card_2.afterUploadImgList;
						let about = this.$refs.about.afterUploadImgList;
						if (!card_1.length) {
							this.$u.toast("请上传身份证正面")
							return
						}
						if (!card_2.length) {
							this.$u.toast("请上传身份证反面")
							return
						}
						// if (!about.length) {
						// 	this.$u.toast("请上传身份证反面")
						// 	return
						// }
						
						let detailInfo={
							"auth_images":card_1 + "," + card_2 + "," + about,
							"username":this.form.username,
							"id_number":this.form.id_number,
						}
				console.log(detailInfo.auth_images,'auth_images')
						let pages = getCurrentPages(); //获取所有页面栈实例列表
						let prevPage = pages[pages.length - 2]; //上一页页面实例
						if (prevPage.route == "pages/apply/index") {
							prevPage.$vm.detailInfo =detailInfo; //修改上一页面的 couponNumber 参数值为 value
							uni.navigateBack({
								delta: 1
							})
						}
						
						
					} else {
						console.log('验证失败');
					}
				});
			},




		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad() {
             this.jiazai()
		}
	};
</script>

<style scoped>
	.page {
		background: #F1F1F1;
		min-height: 100vh;
		padding-bottom: 150rpx;
	}
</style>
